<template>
  <div class="login_bg">
    <div class="login_box">
      <!-- 密码登录表单 -->
      <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="用户名" prop="pass" style="">
          <el-input prefix-icon="el-icon-user" v-model="ruleForm.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="checkPass">
          <el-input prefix-icon="el-icon-lock" type="password" v-model="ruleForm.password" autocomplete="off"></el-input>
          <!-- <el-input prefix-icon="el-icon-delete" color="red" type="password" v-model="ruleForm.password" autocomplete="off"></el-input> -->
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
          <!-- <el-button @click="copy">复制</el-button> -->
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { login } from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth'
export default {
  data () {
    return {
      ruleForm: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm (formName) {
      this.$router.push('/home')
      // this.$refs[formName].validate(async valid => {
      //   if (valid) {
      //     login(this.ruleForm).then(res => {
      //       console.log(res)
      //       if (res.state !== 200) return this.$message.error(res.message)
      //       this.$message.success('登录成功')
      //       setToken(res.message)
      //       window.sessionStorage.setItem('token', res.message)
      //       this.$router.push('/home')
      //     })
      //   } else {
      //     console.log('error submit!!')
      //     return false
      //   }
      // })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
    // copy () {
    //   const copy_text = '第一行需要复制的内容\r\n第二行需要复制的内容'// 拿到想要复制的值
    //   // 使用Clipboard API复制文本到剪贴板中
    //   navigator.clipboard.writeText(copy_text).then(() => {
    //     alert('复制成功！')
    //   }).catch((err) => {
    //     alert('复制失败！')
    //   })
    // }
  }
}
</script>

<style lang="scss" scoped>
.login_bg {
  background-color: #11054F;
  height: 100%;
  .login_box{
    width: 450px;
    height: 300px;
    background-color: #fff;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
    padding: 28px;
    .demo-ruleForm{
      margin-top: 28px;
    }
  }
}
</style>
